********************************************************************************
*   Title: appendix_kinky.do
* Purpose: Produces final graphs and tables for online appendix.
*          See the main() program at the bottom for organization.
* Authors: Qiping Xu, Eric Zwick
*     RAs: Tom (Tianfang) Cui, Laurence O'Brien, Harleen Kaur,
* 		   Francesco Ruggieri, Caleb Wroblewski, Ramiro Rossi
*    Date: 2024-05-02
********************************************************************************

*************************************************
* Figure IA.1: Robustness of Q4 Investment Spikes

capture program drop fig_sawtooth_alt /* %< */
program define fig_sawtooth_alt

	* (a) Alternative Spike Measure
	
	drop if capxq == . | capxq < 0
	drop if fyear < 1984 | fyear > 2016
	keep gvkey fyear fyearquarter fquarter capxq  
	tsset gvkey fyearquarter
	rename fyearquarter fqtr
	format fqtr %tq
	gen qd2f2 = capxq * 400 / (l2.capxq + l1.capxq + f1.capxq + f2.capxq) 
	drop if fyear > 2016
	collapse (median) qd2f2, by(fqtr)
	
	forv j = 99(4)239 {
		local spikes `spikes', `j'
	}
	
	#delimit ;
	twoway 
		(line qd2f2 fqtr) (scatter qd2f2 fqtr if inlist(fqtr `spikes'), mcolor(red)), 
		ytitle("Ratio of Quarterly CAPEX to Average  CAPEX % ")
		xtitle("Fiscal Quarter") 
		ysc(range(75 125)) xsc(range(96 219)) xlabel(99 (40) 219) 
		graphregion(color(white) lwidth(large)) bgcolor(white) legend(off);
	#delimit cr
	graph export "stp`x'sample.pdf", as(pdf)  replace
	
end /* %> */

capture program drop fig_q1_drop /* %< */
program define fig_q1_drop

	* (b) Fiscal Q1 Drop
	
	qvar_prep capx, nogen
	
	drop q2
	gen avecapx = (capxq1 + capxq2 + capxq3 + capxq4) / 4
	
	forvalue i = 1/4 {
		gen q`i' = capxq`i' / avecapx
		count if q`i' > 1.1365
	}
	
	gen totalratio = q1 + q2 + q3 + q4
	replace q4 = (capxq4 + capxqf11) / (avecapx * 2)
	
	qvar_plot, varlab(CAPEX) yscale(75 125) xscale(96 219) xlabel(99 (40) 219) ///
		       output(sawtoothpatternf1.pdf)	
end /* %> */

capture program drop fig_stp_sales /* %< */
program define fig_stp_sales

	* (c) Stable Fiscal Year-End Sales
	
	qvar_prep capx, nogen
	
	drop q2
	gen avecapx = (capxq1 + capxq2 + capxq3 + capxq4) / 4
	
	forvalue i = 1/4 {
		gen q`i' = capxq`i' / avecapx
		count if q`i' > 1.1365
	}
	
	gen totalratio = q1 + q2 + q3 + q4
	drop if sale4_3 > 100
	
	qvar_plot, varlab(CAPEX) yscale(75 125) xscale(96 219) xlabel(99 (40) 219) ///
			   output(stpsales.pdf)
			   
end /* %> */

capture program drop fig_depreciation_spike /* %< */
program define fig_depreciation_spike

	* (d) Fiscal Q4 Book Depreciation Spikes

	gen avedp = dp / 4
	keep gvkey fyear avedp dpq1 dpq2 dpq3 dpq4 
	
	forvalue i = 1/4{
		gen q`i' = dpq`i' / avedp
	}
	
	gen totalratio = q1 + q2 + q3 + q4
	su totalratio, de
	drop if totalratio != 4
	
	qvar_plot, varlab(Depreciation) yscale(75 125) xscale(96 219) ///
			   ylabel(90 (10) 110) xlabel(99 (40) 219) ///
			   output(sawtoothpattern_dp.pdf)
	
end /* %> */

***************************************************
* Figure IA.2: Time Series of Fiscal Q4 R&D Spikes

capture program drop fig_RD /* %< */
program define fig_RD

    qvar_prep xrd, nogen

    drop if naics == ""
    rename naics naics6
	
    forv j = 4(-1)2 {
        gen naics`j' = substr(naics6, 1, `j')
        replace naics`j' = "" if length(naics`j') != `j'
    }
	
    destring naics4-naics2, replace

    tempfile naics4 naics3 naics2
    rename naics4 naics
    merge m:1 naics using "$intermediate/rddecomp.dta"
    preserve

    * Merge imputed R&D spending per NAICS onto firms
    keep if _m == 3
    drop _m
    rename naics naics4

	save `naics4'
	
    forv j = 3(-1)2 {
        restore
        keep if _m == 1  
        drop _m naics
        rename naics`j' naics
        merge m:1 naics using "$intermediate/rddecomp.dta", update replace
        preserve
        keep if inlist(_m, 3, 4, 5)
        drop _m
        rename naics naics`j'
        save `naics`j''
    }
	
    append using `naics3'
    append using `naics4'

    gen salary_q=xrd*compensation_m/4
    
	foreach var of varlist xrdq? {
        replace `var'=`var'-salary_q
    }
	
    replace xrd=xrd*(1-compensation_m)
    qvar_prep xrd, nofilter

    qvar_plot, varlab("RD") ysc(75 125) xsc(116 215) xlab(116 (24) 214) ///
		       output(sawtoothpattern_rd.pdf) 
end /* %> */

**************************************************
* Figure IA.3: Q4 Spikes and Earnings Management 

capture program drop fig_surprise /* %< */
program define fig_surprise

    tempfile orig
    save `orig'
	
	replace capx4_3 = capx4_3/100
    drop if missing(capx4_3) | missing(eps_median_surprise_q4)
    drop if eps_median_surprise_q4 < -2 | eps_median_surprise_q4>1

    foreach type in median mean {
        trim_tails eps_`type'_surprise_q4, level(0.01)
        drop *_ut
    }

    * Results: yes, firms beats their forecasts a lot 
	* increase their q4 capx a lot compared to the first three quarters. 
    binscatter capx4_3 eps_median_surprise_q4, median n(100) line(none) ///
		xli(0, lc(gray)) ytitle("Median CAPEX 4/3") ///
		xtitle ("Bin of Q4 Earnings Surprise ($)") yscale(range(100 140)) ///
		ylabel(100 (20) 140) xscale(range(-1 1)) xlabel(-1 (0.5) 1) ///
        graphregion(color(white) lwidth(large)) bgcolor(white) legend(off)  
    graph export "q4_earnings_surprise.pdf", as(pdf) replace

    use `orig', clear

end /* %> */


**************************************************
* Figure IA.4: Q4 Spikes and TRA86
capture program drop fig_tra86 /* %< */
program define fig_tra86
	
	replace capx4_3 = capx4_3/100
	tempfile orig
	save `orig'
	drop if fyear > 2000
    forvalues i = 1984/1999 {
        gen dum`i' = (fyear == `i')
    }
    eststo clear
    eststo tra86: areg capx4_3 $controls1 dum*, absorb(gvkey) cluster(gvkey)

	coefplot tra86,  vertical  drop(_cons $controls1) ///
		rename(dum1984=84 dum1985=85 dum1986=86 dum1987=87 dum1988=88 dum1989=89 ///
			   dum1990=90 dum1991=91 dum1992=92 dum1993=93 dum1994=94 dum1995=95 ///
			   dum1996=96 dum1997=97 dum1998=98 dum1999=99) ///
		yline(0) recast(connected) graphregion(color(white)) bgcolor(white) ///
		ytitle("Yearly Regression Estimate") xtitle("Year") xsize(6.5) ///
		addplot(scatteri -10 04.5 20 04.5, recast(line) lcolor(gs6) ///
		lpattern(dash) lstyle(foreground) || scatteri -10 06.5 20 06.5, ///
		recast(line) lcolor(gs6) lpattern(dash) lstyle(foreground))
	graph export "tra86long_noshade.pdf", replace
	
end /* %> */



***************************************************************************
* Figure IA.5: Cumulative Effect of Q4 CAPEX Spikes, Alternative Bandwidths 
* Note: This figure uses internal data 

capture program drop fig_cum_bandwidth/*%<*/
program define fig_cum_bandwidth

    * Bandwidth graph
    load_analysis_data cum_bandwidth_app

    forv i=3/3 {
        gen upper`i' = b`i' + 1.96 * se`i'
        gen lower`i' = b`i' - 1.96 * se`i'
    }

    #delimit ;
    twoway 
        (connect b3 i,  msize(small))
        (rline upper3 lower3 i, pstyle(p1) lp(dash)) if i <= 50,
        yline(0) xline(10, lp(dash))
        ytitle("Coefficient on D(Forward 3Y)*Taxable Spiker")
        xtitle("Bandwidth (\$ Millions)") $gpr legend(off);
    #delimit cr
    graph export "q4capxpre_bandwidth.pdf", replace

end/*%>*/


*******************************************************************
* Figure IA.6: Discount rate comparative statics in model simulations

capture program drop fig_sim_drift/*%<*/
program define fig_sim_drift

    load_analysis_data model_drift

	tempfile orig
	save `orig'
	
	foreach version in inflation drift full_beta975 {
	    
		use `orig', clear
		keep if version == "`version'"

		* Only keep first 25 periods and investment data
		drop if period > 25
		drop gos ktax k 
		capture drop kbar g

		* Calculate average invratio for each quarter
		collapse (mean) inv, by(year quarter period)

		* Calculate average yearly investment for each year
		egen avg_year_investment = mean(inv), by(year)
	
		* Calculate aggregate invratio for each period
		gen invratio = 100 * (inv / avg_year_investment)

		* Rename variables to make it clear which version they're from
		ren invratio invratio_`version'
		
		* Create a point showing the investment in quarter 4 for each year
		gen invratio_q4_`version' = invratio_`version' if quarter == 4

		* Make variable names lowercase
		rename *, lower
				
		tempfile agg_spike_`version'
		save "`agg_spike_`version''"
	}
	
	* Merge the datasets together 
	use "`agg_spike_inflation'", clear
	merge 1:1 year quarter using "`agg_spike_drift'", assert(3) nogen
	merge 1:1 year quarter using "`agg_spike_full_beta975'", assert(3) nogen
	
	* Make graph
	#delimit ;
	graph twoway
		(line invratio_full_beta975 period, lcolor(dknavy) lpattern(solid) lwidth(medthick))
		(scatter invratio_q4_full_beta975 period, mcolor(dknavy) msize(small) msymbol(s))
		(line invratio_drift period, lcolor(forest_green) lpattern(dash))
		(scatter invratio_q4_drift period, mcolor(forest_green) msize(small) msymbol(o))
		(line invratio_inflation period, lcolor(cranberry) lpattern(dash_dot))
		(scatter invratio_q4_inflation period, mcolor(cranberry) msize(small) msymbol(t)),
		graphregion(color(white) lwidth(large)) bgcolor(white)
		legend(order(1 "Full" 3 "Low Risk Depreciation" 5 "Inflation") 
        rows(1) pos(6) region(lcolor(black)))
		ytitle("Aggregate Investment Ratio") name(Agg_investment_fig6 , replace) xtitle("Period");
	#delimit cr
	graph export "agg_spike_graph_drift.pdf", replace

end/*%>*/

*******************************************************************
* Figure IA.7: Time Series of Immediate Benefits from Depreciation

capture program drop fig_losses /*%<*/
program define fig_losses
	
	/* vars are: 
    year            int     %8.0g                
    capx4_3         float   %9.0g                 
    expect_nip      float   %9.0g                 
    net_income_plus float   %9.0g                 
    positive_enip   float   %9.0g                 
    positive_nip    float   %9.0g                 
    positive_ni
    */

    replace positive_enip = 100 * positive_enip
    replace positive_nip = 100 * positive_nip
    replace positive_ni = 100 * positive_ni

    * year = -1 for the overall statistics
    drop if year == -1

    set obs `=_N + 4'
    replace year = 2000.52 if _n == _N - 3
    replace year = 2001.5 if _n == _N - 2
    replace year = 2007.52 if _n == _N - 1
    replace year = 2009.5 if _n == _N
    
    gen yshade = .
    replace yshade = 85 if _n >= _N - 3

    #delimit ;
    twoway 
        (area yshade year if year <= 2002, base(37) color("230 230 230"))
        (area yshade year if year > 2002, base(37) color("230 230 230"))
        (connect positive_enip year, lc(navy) mc(navy) msym(o))
        (connect positive_nip year, lc(maroon) mc(maroon) msym(s))
        (connect positive_ni year, lc(forest_green) mc(forest_green) msym(t)),
        xline(2000.5 2004.5 2007.5, lp(dash) lc(gray))
        yscale(range(45 80)) ylab(40(10)80)
        xscale(range(1991.5 2010.5)) xlab(1992(2)2010)
        $graphconfig xtitle("") ytitle("Share of Observations (%)")
        legend(
            order(4 "Positive Net Income Before Depreciation and Potential NOL"
                  5 "Positive Net Income After Depreciation Before Potential NOL"
                  3 "Positive Net Income Before Depreciation After Potential NOL")
            col(1)
              )
        plotregion(margin(sides))
        xsize(7);
    #delimit cr
    graph export "loss_share_yearly.pdf", replace

end /*%>*/

****************************************************************
* Table 6: Fiscal Q4 CAPEX Spikes and the Tax Reform Act of 1986

capture program drop table_taxreform /* %< */
program define table_taxreform

	replace capx4_3 = capx4_3 / 100

	gen d8486 = (fyear == 1984 | fyear == 1985 | fyear == 1986)
	gen d87 = (fyear == 1987)
	gen d8487 = (fyear == 1984 | fyear == 1985 | fyear == 1986 | fyear == 1987)
	gen D200 = (capx4_3 >= 200) * 100
	replace D200 = . if capx4_3 == .
	la var D200 "CAPEX4/3>200%"
	
	gen D160 = (capx4_4 >= 160) * 100
	replace D160 = . if capx4_4 == .
	la var D160 "CAPEX4/Total>40%"
	
	label var d8487 "D(1984-1987)"
	replace capx4_y = (1 / (300 / capx4_3 + 1)) * 100
	replace capx4_4 = capx4_y * 4
	
	eststo tracapx4_3: qui reghdfe capx4_3 d8487, absorb(gvkey) cluster(gvkey)
	qui: estadd local firm "Yes", replace
	qui: estadd local controls "No", replace
	qui: estadd local period "84-16", replace
	   
	eststo traccapx4_3: qui reghdfe capx4_3  d8487 $controls1 , ///
						absorb(gvkey) cluster(gvkey )
	qui: estadd local firm "Yes", replace
	qui: estadd local controls "Yes", replace
	qui: estadd local period "84-16", replace

	eststo tra200capx4_3: qui reghdfe D200 d8487 , ///
						  absorb(gvkey) cluster(gvkey)
	qui: estadd local firm "Yes", replace
	qui: estadd local controls "No", replace
	qui: estadd local period "84-16", replace

	eststo tra200ccapx4_3: qui reghdfe D200  d8487  $controls1 , ///
						   absorb(gvkey) cluster(gvkey )
	qui: estadd local firm "Yes", replace
	qui: estadd local controls "Yes", replace
	qui: estadd local period "84-16", replace
	
	preserve
		drop if fyear>2000
		eststo tra2000capx4_3: qui reghdfe capx4_3  d8487 , ///
							   absorb(gvkey) cluster(gvkey)
		qui: estadd local firm "Yes", replace
		qui: estadd local controls "No", replace
		qui: estadd local period "84-00", replace
		eststo tra2000ccapx4_3: qui reghdfe capx4_3  d8487  $controls1 , ///
								absorb(gvkey) cluster(gvkey)
		qui: estadd local firm "Yes", replace
		qui: estadd local controls "Yes", replace
		qui: estadd local period "84-00", replace
	restore
	preserve
		drop if fyear>1992
		eststo tra1993capx4_3: qui reghdfe capx4_3  d8487 , ///
							   absorb(gvkey) cluster(gvkey)
		qui: estadd local firm "Yes", replace
		qui: estadd local controls "No", replace
		qui: estadd local period "84-92", replace
		eststo tra1993ccapx4_3: qui reghdfe capx4_3  d8487  $controls1 , ///
								absorb(gvkey) cluster(gvkey)
		qui: estadd local firm "Yes", replace
		qui: estadd local controls "Yes", replace
		qui: estadd local period "84-92", replace
	restore
	 
	esttab tra1993capx4_3 tra1993ccapx4_3 tra2000capx4_3 tra2000ccapx4_3 tracapx4_3 ///
		   traccapx4_3  tra200capx4_3  tra200ccapx4_3 using "taxchange.tex", ///
	scalar("N Observations" "r2_a Adj R-Squared" "controls Controls" ///
		   "firm Firm FE"  "period Period") ///
	cells(b(star fmt(%9.1f)) se(par) ) ar2(%8.2f) starlevels(* .10 ** .05 *** .01 ) ///
	keep(d8487) style(tex) replace  ///
	label collabels(none) varlabels(_cons Constant) nodep nomti

end /* %> */


***********************************************************
* Table IA.7: Decomposing the Investment-Cash Flow Sensitivity

capture program drop table_icf /* %< */
program define table_icf

	tsset gvkey fyear
	gen lq=l.q2
	gen lat=l.at
    eststo cf: xi: qui areg capx2at cf2at lq i.fyear, absorb(gvkey) cluster(gvkey)
    qui: estadd local firm "Yes"
    qui estadd local year "Yes" 

	keep gvkey fyear lq lat
	tempfile accountingy
	save "`accountingy'"

	use "$analysis/Compustat/fundq.dta", clear
	drop if fyear < 1984 | fyear > 2016
	drop if atq < 10 | atq == .
	destring gvkey, replace
	merge n:1 gvkey using "$analysis/Compustat/compustat_company.dta", nogen keep(1 3)
	drop if substr(sic, 1, 1) == "6"
	destring sic, replace
	drop if sic == .
	drop if (sic >= 4900 & sic <= 4949)
	keep if stko == 0 | stko == 3
	destring gvkey, replace
	gen fyearquarter = yq(fyearq, fqtr)
	bysort gvkey fyearquarter: keep if _n == 1
	tsset gvkey fyearquarter
	gen latq = l.atq
	foreach v in  capx  dpc {
		gen `v'q = `v'y if fqtr == 1
		replace `v'q = S.`v'y if fqtr >= 2 & fqtr <= 4
	}
	replace dpcq = 0 if dpcq ==. | dpcq < 0
	replace txdbq = 0 if txdbq == .
	gen cfq = ibq + dpcq
	gen q_q = (atq + cshoq * prccq - ceqq - txdbq) / atq
	rename fyearq fyear
	rename fqtr fquarter
	gen yearquarter = yq(year(datadate), quarter(datadate))
	keep gvkey fyear fyearquarter yearquarter fquarter cfq dpcq capxq q_q latq
	gen lq_q = l.q_q
	
	merge m:1 gvkey fyear using  "`accountingy'", keep(3) nogen
	gen cf2at = cfq / lat
	gen capx2atq = capxq / lat

	foreach v in q_q cf2at capx2atq {
		winsor2 `v', cut(1 99) replace
		su `v', de
	}

	gen qtr2 = (fquarter == 2)
	gen qtr3 = (fquarter == 3)
	gen qtr4 = (fquarter == 4)
	gen cf2atq2 = cf2at * qtr2
	gen cf2atq3 = cf2at * qtr3
	gen cf2atq4 = cf2at * qtr4

	la var cf2at " $\frac{Cash Flow}{Asset}$"
	la var cf2atq2 " $\frac{Cash Flow}{Asset}*Q2$"
	la var cf2atq3 " $\frac{Cash Flow}{Asset}*Q3$"
	la var cf2atq4 " $\frac{Cash Flow}{Asset}*Q4$"
	la var lq "Tobin's Q"

	eststo cf1: xi: qui areg capx2atq  cf2at cf2atq2 cf2atq3  cf2atq4 lq i.yearquarter, ///
							 absorb(gvkey) cluster(gvkey)
	qui: estadd local firm "Yes"
	qui estadd local quarter "Yes" 

	eststo cf2: xi: qui areg capx2atq  cf2at cf2atq4  lq i.yearquarter, ///
							 absorb(gvkey) cluster(gvkey)
	qui: estadd local firm "Yes"
	qui estadd local quarter "Yes" 

	esttab cf cf2 cf1 using "icf.tex", ///
		scalar("N Observations" "r2_a Adj R-Squared" "firm Firm FE" "year Year FE" ///
		       "quarter Year-Quarter FE") ///
		keep(cf2at cf2atq2 cf2atq3 cf2atq4 lq) cells(b(star fmt(%8.3f)) se(par)) ///
		starlevels(* .10 ** .05 *** .01)  ///
		order(cf2at cf2atq2 cf2atq3 cf2atq4)style(tex) replace  ///
		label collabels(none) varlabels(_cons Constant) nomti nodep
		
end /* %> */

************************************************
* Table IA.9: Investment Spikes and Debt Spikes

capture program drop table_debtspikes /* %< */
program define table_debtspikes

	* Is debt issuance corrlated with CAPEX spikes? 
 
    preserve

    * Standardize regressor
	la var capx4_3 "CAPEX Q4/Ave(Q1-Q3)\%"
	foreach x of varlist capx4_3{
		egen `x'sd=sd(`x')
		gen `x'_sd=`x'/`x'sd
		replace `x'=`x'_sd
	}
    
    foreach x of varlist bd4_3 dltis4_3 dltt4_3 dlc4_3{
		eststo  `x':  qui xi: reghdfe   `x'  capx4_3 , absorb(gvkey fyear) cluster(gvkey)
		qui: estadd local year "Yes"
		qui: estadd local firm "Yes"
	}
	esttab  dltis4_3   dltt4_3  dlc4_3 bd4_3  , keep(capx4_3) ///
		cells(b(star fmt(%9.2f)) se(par) )     starlevels(* .10 ** .05 	*** .01 )

    * Robustness with december fiscal year end
    drop if cal_month==12
	foreach x of varlist bd4_3 dltis4_3 dltt4_3 dlc4_3{
		eststo  `x'2:  qui xi: reghdfe   `x'  capx4_3 , absorb(gvkey fyear) cluster(gvkey)
		qui: estadd local year "Yes"
		qui: estadd local firm "Yes"
	}
	esttab  dltis4_32  dltt4_32  dlc4_32 bd4_32 , keep(capx4_3) ///
		cells(b(star fmt(%9.2f)) se(par) )     starlevels(* .10 ** .05 *** .01 )
	

    foreach table in 3 32 {
    #delimit ;
    esttab  dltis4_`table'  dltt4_`table'  dlc4_`table' bd4_`table', keep(capx4_3)
        cells(b(star fmt(%9.2f)) se(par) ) starlevels(* .10 ** .05 *** .01 );

    esttab dltis4_`table'  dltt4_`table'  dlc4_`table' bd4_`table'
        using "debtissue4`table'.tex",
        scalar("N Observations" "r2_a Adj R-Squared" "year Year FE" "firm Firm FE")
        keep(capx4_3) cells(b(star fmt(%9.2f)) se(par) )
        starlevels(* .10 ** .05 *** .01 ) style(tex) replace
        label collabels(none) varlabels(_cons Constant) nodep
        mtitle("Debt Issues $\frac{Q4}{Ave(Q1-Q3)}$"
               "Long-term Debt $\frac{Q4}{Ave(Q1-Q3)}$"
               "Current Debt $\frac{Q4}{Ave(Q1-Q3)}$"
               "Total Debt $\frac{Q4}{Ave(Q1-Q3)}$");
    #delimit cr
    }

end /* %> */

*****************************************************
*Table IA.10: Comparative Statics for the Full Model

capture program drop table_model_compstatics /* %< */
program define table_model_compstatics

	* Just keep full versions of the model
	keep if strpos(version, "full") > 0

	* Calculate average investment ratios by version 
	egen double avg_year_investment = mean(inv), by(year firm_no version)
	keep if quarter == 4
	gen invratio = 100 * (inv / avg_year_investment)

	* Collapse to get mean investment ratios by version
	collapse (mean) invratio, by(version)

	* Make the columns for the table
	gen tau = "0.21" if version == "full_beta975_tax21"
	replace tau = "0.46" if version == "full_beta975_tax46"
	replace tau = "0.35" if missing(tau)

	gen delta_hat = "0.06" if version == "full_beta975_depr06"
	replace delta_hat = "0.18" if version == "full_beta975_depr18"
	replace delta_hat = "0.119" if missing(delta_hat)

	gen tax_credit = "YES" if version == "full_beta975_taxcredit"
	replace tax_credit = "NO" if missing(tax_credit)

	* Original beta 0.975. Low beta = 0.9725
	* added full_beta09725
    gen beta = "0.975"
    replace beta = "0.9725" if version == "full_beta09725"

	replace version = "Full" if version == "full_beta975"
	replace version = "Low Tax Depreciation Rate" if version == "full_beta975_depr06"
	replace version = "High Tax Depreciation Rate" if version == "full_beta975_depr18"
	replace version = "Low Tax Rate" if version == "full_beta975_tax21"
	replace version = "High Tax Rate" if version == "full_beta975_tax46"
	replace version = "Tax Credit" if version == "full_beta975_taxcredit"
    replace version = "Low Discount Factor" if version == "full_beta09725"

	gen inv_ratio = string(invratio, "%05.2f")
	drop invratio

	label var tau "\(\tau\)"
	label var delta_hat "\(\hat{\delta}\)"
	label var tax_credit "Tax Credit?"
    label var beta "\beta\^4"
	label var inv_ratio "Mean Spike"
	label var version "Model Version"

	order version delta_hat tau tax_credit beta inv_ratio

	texsave using "comp_statics.tex", varlabels replace width("\textwidth") frag 

end /* %> */

********************************************************************************
* Main
********************************************************************************
	
capture program drop main /* %> */
program define main

	capture log c
	log using "$outputdir/appendix_kinky.log", replace
    cd $outputdir
	
	global controls1 mkt2bk res2at capx2ppe sale4_3 l_at
	global controls2 mkt2bk res2at capx2ppe sale4_3 ebitda2at l_at
	global controls3 mkt2bk res2at ebitda2at l_at
	
	global graphconfig graphregion(color(white) lwidth(large)) bgcolor(white)
	
    *************************************************************
    * Appendix Graphs
    *************************************************************

	*** Figure IA.I ***
	load_analysis_data quarterly_capx
	fig_sawtooth_alt
	
	load_analysis_data capx_trim5
	fig_q1_drop
	
	load_analysis_data capx_trim5
	fig_stp_sales
	
	load_analysis_data capx_trim5
	fig_depreciation_spike
	
	*** Figure IA.2 ***
	load_analysis_data capx_trim5
	fig_RD
	
	*** Figure IA.3 *** 
	load_analysis_data capx_trim5
	fig_surprise
	
	*** Figure IA.4 *** 
	load_analysis_data capx_trim5
	fig_tra86
	
	*** Figure IA.5 *** 
*	fig_cum_bandwidth    //uses internal data 

	*** Figure IA.6 *** 
    fig_sim_drift
	
	*** Figure IA.7 ***
*	load_analysis_data losses.  //uses internal data 
*	fig_losses
	
	*************************************************************
    * Appendix Tables
    *************************************************************

	*** Table IA.1 *** // no data used
	
	*** Table IA.2 *** // uses internal data
	
	*** Table IA.3 ***  //uses internal data 
	
	*** Table IA.4 *** // no data used

	*** Table IA.5 *** // no data used
	
	*** Table IA.6 ***
	load_analysis_data capx_trim5
	table_taxreform
	
	
	*** Table IA.7 ***
	load_analysis_data accountingy
	table_icf
	
	
	*** Table IA.8 *** //uses internal data
	

	*** Table IA.9 *** 
	load_analysis_data capx_trim5
	table_debtspikes
	
	*** Table IA.10 ***
	load_analysis_data model
	table_model_compstatics
	

	
	
	cd $localcodedir
    log close
	
end /* %> */
